package com.sks.bean.pojo;

import static javax.persistence.GenerationType.IDENTITY;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.hibernate.annotations.Where;

import com.sks.bean.privilege.Employee;
import com.sks.bean.uploadfile.UploadFile;

/**
 * House entity.
 * 
 * @author MyEclipse Persistence Tools
 */
@Entity
@JsonIgnoreProperties(value={"hibernateLazyInitializer"}) 
@Table(name = "house", uniqueConstraints = { @UniqueConstraint(columnNames = { "title" }) })
public class House implements java.io.Serializable {
	
	public static String HOUSE_STATUS_NONE_SUBMIT = "noneSubmit";//未提交（前台专用）
	
	public static String HOUSE_STATUS_NONE_AUDIT = "noneAudit";//未审核
	
	public static String HOUSE_STATUS_AUDITED = "audited";//已审核
	
	public static String HOUSE_STATUS_PUBLISHED = "published";//已发布
	
	public static String HOUSE_STATUS_FINISHED = "finished";//已完成交易
	
	public static String HOUSE_STATUS_INVALIDATE = "invalidate";//已失效
	
	public static Integer HOUSE_TRANSACTION_STATUS_RENT = 0;
	
	public static Integer HOUSE_TRANSACTION_STATUS_SALE = 1;
	
	public static Integer HOUSE_TRANSACTION_STATUS_BOTH = 2;

	// Fields

	private Integer houseId;
	private Users users;
	private PayType salePayType;
	private HouseType houseType;
	private MetroStation metroStation;
	private Employee employee;
	private PayType rentPayType;
	private PropertyType propertyType;
	private Area area;
	private Building building;
	private String title;
	private String community;
	private String address;
	private Double space;
	private Integer floorAll;
	private Integer floorAt;
	private Date beginDate;
	private Date indate;
	private String mapInfo;
	private String intro;
	private String managePrice;
	private Integer hits;
	private String linkMan;
	private String mobile;
	private Integer transaStatus;
	private Double rentPrice;
	private Integer rentMode;
	private String rentShareInfo;
	private String houseProperty;
	private Double salePrice;
	private String houseStatus;
	private Date createTime;
	private Date auditTime;
	private Date publishTime;
	private Date lastUpdateTime;
	private Date finishTime;
	private Boolean isHot;
	private String remark;
	private Set<Config> configs = new HashSet<Config>(0);
	private List<Comment> comments = new ArrayList<Comment>(0);
	private List<UploadFile> pictures = new ArrayList<UploadFile>(0);
	private List<AuditHistory> auditHistory = new ArrayList<AuditHistory>(0);
	
	private List<UploadFile> videos = new ArrayList<UploadFile>(0);

	private Integer userId;
	private Integer salePayTypeId;
	private Integer houseTypeId;
	private Integer metroStationId;
	private Integer metroId;
	private String employeeName;
	private Integer rentPayTypeId;
	private Integer propertyTypeId;
	private Integer areaId;
	private Integer buildingId;

	// Constructors

	/** default constructor */
	public House() {
	}

	/** minimal constructor */
	public House(Integer houseId, String title, String address, Double space,
			Integer transaStatus, String houseStatus, Date createTime,
			Date lastUpdateTime) {
		this.setHouseId(houseId);
		this.title = title;
		this.address = address;
		this.space = space;
		this.transaStatus = transaStatus;
		this.houseStatus = houseStatus;
		this.createTime = createTime;
		this.lastUpdateTime = lastUpdateTime;
	}

	/** full constructor */
	public House(Integer houseId, Users users, PayType salePayType,
			HouseType houseType, MetroStation metroStation, Employee employee,
			PayType rentPayType, PropertyType propertyType, Area area,
			Building building, String title, String community, String address,
			Double space, Integer floorAll, Integer floorAt, Date beginDate,
			Date indate, String mapInfo, String intro, String managePrice,
			Integer hits, String linkMan,
			String mobile, Integer transaStatus, Double rentPrice,
			Integer rentMode, String rentShareInfo, String houseProperty,
			Double salePrice, String houseStatus, Date createTime,
			Date auditTime, Date publishTime, Date lastUpdateTime,
			Boolean isHot, String remark, Set<Config> configs,
			List<Comment> comments) {
		this.setHouseId(houseId);
		this.users = users;
		this.salePayType = salePayType;
		this.houseType = houseType;
		this.metroStation = metroStation;
		this.employee = employee;
		this.rentPayType = rentPayType;
		this.propertyType = propertyType;
		this.area = area;
		this.building = building;
		this.title = title;
		this.community = community;
		this.address = address;
		this.space = space;
		this.floorAll = floorAll;
		this.floorAt = floorAt;
		this.beginDate = beginDate;
		this.indate = indate;
		this.mapInfo = mapInfo;
		this.intro = intro;
		this.managePrice = managePrice;
		this.hits = hits;
		this.linkMan = linkMan;
		this.mobile = mobile;
		this.transaStatus = transaStatus;
		this.rentPrice = rentPrice;
		this.rentMode = rentMode;
		this.rentShareInfo = rentShareInfo;
		this.houseProperty = houseProperty;
		this.salePrice = salePrice;
		this.houseStatus = houseStatus;
		this.createTime = createTime;
		this.auditTime = auditTime;
		this.publishTime = publishTime;
		this.lastUpdateTime = lastUpdateTime;
		this.isHot = isHot;
		this.remark = remark;
		this.configs = configs;
		this.comments = comments;
	}

	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "houseId", unique = true, nullable = false, insertable = true, updatable = true)
	public Integer getHouseId() {
		return this.houseId;
	}

	public void setHouseId(Integer houseId) {
		this.houseId = houseId;
	}
	@JsonIgnore
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "userId", unique = false, nullable = true, insertable = true, updatable = true)
	public Users getUsers() {
		return this.users;
	}

	public void setUsers(Users users) {
		if (null != users) {
			this.setUserId(users.getUserId());
		}
		this.users = users;
	}
	@JsonIgnore
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "salePayTypeId", unique = false, nullable = true, insertable = true, updatable = true)
	public PayType getSalePayType() {
		return this.salePayType;
	}

	public void setSalePayType(PayType salePayType) {
		if (null != salePayType) {
			this.setSalePayTypeId(salePayType.getPayTypeId());
		}
		this.salePayType = salePayType;
	}

	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "houseTypeId", unique = false, nullable = true, insertable = true, updatable = true)
	public HouseType getHouseType() {
		return this.houseType;
	}

	public void setHouseType(HouseType houseType) {
		if (null != houseType) {
			this.setHouseTypeId(houseType.getHouseTypeId());
		}
		this.houseType = houseType;
	}
	@JsonIgnore
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "stationId", unique = false, nullable = true, insertable = true, updatable = true)
	public MetroStation getMetroStation() {
		return this.metroStation;
	}

	public void setMetroStation(MetroStation metroStation) {
		if (null != metroStation) {
			this.setMetroStationId(metroStation.getStationId());
			if (null != metroStation.getMetroByMetroId()) {
				this.setMetroId(metroStation.getMetroByMetroId().getMetroId());
			} else if (null != metroStation.getMetroByMetroId1()) {
				this.setMetroId(metroStation.getMetroByMetroId1().getMetroId());
			} else {
				this.setMetroId(null);
			}
		} else {
			this.setMetroStationId(null);
		}
		this.metroStation = metroStation;
	}
	@JsonIgnore
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "employee", unique = false, nullable = true, insertable = true, updatable = true)
	public Employee getEmployee() {
		return this.employee;
	}

	public void setEmployee(Employee employee) {
		if (null != employee) {
			this.setEmployeeName(employee.getUsername());
		}
		this.employee = employee;
	}
	
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "rentPayTypeId", unique = false, nullable = true, insertable = true, updatable = true)
	public PayType getRentPayType() {
		return this.rentPayType;
	}

	public void setRentPayType(PayType rentPayType) {
		if (null != rentPayType) {
			this.setRentPayTypeId(rentPayType.getPayTypeId());
		}
		this.rentPayType = rentPayType;
	}
	@JsonIgnore
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "propertyTypeId", unique = false, nullable = true, insertable = true, updatable = true)
	public PropertyType getPropertyType() {
		return this.propertyType;
	}

	public void setPropertyType(PropertyType propertyType) {
		if (null != propertyType) {
			this.setPropertyTypeId(propertyType.getPropertyTypeId());
		}
		this.propertyType = propertyType;
	}
	@JsonIgnore
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "areaId", unique = false, nullable = true, insertable = true, updatable = true)
	public Area getArea() {
		return this.area;
	}

	public void setArea(Area area) {
		this.area = area;
	}
	@JsonBackReference
	@ManyToOne(cascade = {}, fetch = FetchType.LAZY)
	@JoinColumn(name = "buildingId", unique = false, nullable = true, insertable = true, updatable = true)
	public Building getBuilding() {
		return this.building;
	}

	public void setBuilding(Building building) {
		this.building = building;
	}

	@Column(name = "title", unique = true, nullable = false, insertable = true, updatable = true, length = 100)
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
	@JsonIgnore
	@Column(name = "community", unique = false, nullable = true, insertable = true, updatable = true, length = 100)
	public String getCommunity() {
		return this.community;
	}

	public void setCommunity(String community) {
		this.community = community;
	}

	@Column(name = "address", unique = false, nullable = false, insertable = true, updatable = true, length = 200)
	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	@Column(name = "space", unique = false, nullable = false, insertable = true, updatable = true, precision = 22, scale = 0)
	public Double getSpace() {
		return this.space;
	}

	public void setSpace(Double space) {
		this.space = space;
	}

	@Column(name = "floorAll", unique = false, nullable = true, insertable = true, updatable = true)
	public Integer getFloorAll() {
		return this.floorAll;
	}

	public void setFloorAll(Integer floorAll) {
		this.floorAll = floorAll;
	}

	@Column(name = "floorAt", unique = false, nullable = true, insertable = true, updatable = true)
	public Integer getFloorAt() {
		return this.floorAt;
	}

	public void setFloorAt(Integer floorAt) {
		this.floorAt = floorAt;
	}
	@JsonIgnore
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "beginDate", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
	public Date getBeginDate() {
		return this.beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}
	@JsonIgnore
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "indate", unique = false, nullable = true, insertable = true, updatable = true, length = 10)
	public Date getIndate() {
		return this.indate;
	}

	public void setIndate(Date indate) {
		this.indate = indate;
	}
	@JsonIgnore
	@Column(name = "mapInfo", unique = false, nullable = true, insertable = true, updatable = true, length = 100)
	public String getMapInfo() {
		return this.mapInfo;
	}

	public void setMapInfo(String mapInfo) {
		this.mapInfo = mapInfo;
	}
	@JsonIgnore
	@Lob
	@Basic(fetch=FetchType.LAZY)
	@Column(name = "intro", unique = false, nullable = true, insertable = true, updatable = true)
	public String getIntro() {
		return this.intro;
	}

	public void setIntro(String intro) {
		this.intro = intro;
	}
	@JsonIgnore
	@Column(name = "managePrice", unique = false, nullable = true, insertable = true, updatable = true, length = 200)
	public String getManagePrice() {
		return this.managePrice;
	}

	public void setManagePrice(String managePrice) {
		this.managePrice = managePrice;
	}
	@JsonIgnore
	@Column(name = "hits", unique = false, nullable = true, insertable = true, updatable = true)
	public Integer getHits() {
		return this.hits;
	}

	public void setHits(Integer hits) {
		this.hits = hits;
	}
	@JsonIgnore
	@Column(name = "linkMan", unique = false, nullable = true, insertable = true, updatable = true, length = 40)
	public String getLinkMan() {
		return this.linkMan;
	}

	public void setLinkMan(String linkMan) {
		this.linkMan = linkMan;
	}

	@Column(name = "mobile", unique = false, nullable = true, insertable = true, updatable = true, length = 40)
	public String getMobile() {
		return this.mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	@JsonIgnore
	@Column(name = "transaStatus", unique = false, nullable = false, insertable = true, updatable = true)
	public Integer getTransaStatus() {
		return this.transaStatus;
	}

	public void setTransaStatus(Integer transaStatus) {
		this.transaStatus = transaStatus;
	}

	@Column(name = "rentPrice", unique = false, nullable = true, insertable = true, updatable = true)
	public Double getRentPrice() {
		return this.rentPrice;
	}

	public void setRentPrice(Double rentPrice) {
		this.rentPrice = rentPrice;
	}

	@Column(name = "rentMode", unique = false, nullable = true, insertable = true, updatable = true)
	public Integer getRentMode() {
		return this.rentMode;
	}

	public void setRentMode(Integer rentMode) {
		this.rentMode = rentMode;
	}
	@JsonIgnore
	@Column(name = "rentShareInfo", unique = false, nullable = true, insertable = true, updatable = true, length = 1000)
	public String getRentShareInfo() {
		return this.rentShareInfo;
	}

	public void setRentShareInfo(String rentShareInfo) {
		this.rentShareInfo = rentShareInfo;
	}

	@Column(name = "houseProperty", unique = false, nullable = true, insertable = true, updatable = true, length = 100)
	public String getHouseProperty() {
		return this.houseProperty;
	}

	public void setHouseProperty(String houseProperty) {
		this.houseProperty = houseProperty;
	}

	@Column(name = "salePrice", unique = false, nullable = true, insertable = true, updatable = true)
	public Double getSalePrice() {
		return this.salePrice;
	}

	public void setSalePrice(Double salePrice) {
		this.salePrice = salePrice;
	}
	@JsonIgnore
	@Column(name = "houseStatus", unique = false, nullable = false, insertable = true, updatable = true, length = 10)
	public String getHouseStatus() {
		return this.houseStatus;
	}

	public void setHouseStatus(String houseStatus) {
		this.houseStatus = houseStatus;
	}
	@JsonIgnore
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "createTime", unique = false, nullable = false, insertable = true, updatable = true, length = 19)
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	@JsonIgnore
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "auditTime", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
	public Date getAuditTime() {
		return this.auditTime;
	}

	public void setAuditTime(Date auditTime) {
		this.auditTime = auditTime;
	}
	@JsonIgnore
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "publishTime", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
	public Date getPublishTime() {
		return this.publishTime;
	}

	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}
	@JsonIgnore
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "lastUpdateTime", unique = false, nullable = false, insertable = true, updatable = true, length = 19)
	public Date getLastUpdateTime() {
		return this.lastUpdateTime;
	}

	public void setLastUpdateTime(Date lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}
	@JsonIgnore
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "finishTime", unique = false, nullable = true, insertable = true, updatable = true, length = 19)
	public Date getFinishTime() {
		return finishTime;
	}

	public void setFinishTime(Date finishTime) {
		this.finishTime = finishTime;
	}
	@JsonIgnore
	@Column(name = "isHot", unique = false,  insertable = true, updatable = true)
	public Boolean getIsHot() {
		return this.isHot;
	}

	public void setIsHot(Boolean isHot) {
		this.isHot = isHot;
	}
	@JsonIgnore
	@Column(name = "remark", unique = false, nullable = true, insertable = true, updatable = true, length = 500)
	public String getRemark() {
		return this.remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	/*@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "house")
	//@Transient
	public Set<HouseConfig> getHouseConfigs() {
		return this.houseConfigs;
	}

	public void setHouseConfigs(Set<HouseConfig> houseConfigs) {
		this.houseConfigs = houseConfigs;
	}*/
	@JsonIgnore
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "house_config", joinColumns = { @JoinColumn(name = "houseId", nullable = false, updatable = true) }, inverseJoinColumns = { @JoinColumn(name = "configId", nullable = false, updatable = true) })
	public Set<Config> getConfigs() {
		return this.configs;
	}

	public void setConfigs(Set<Config> configs) {
		this.configs = configs;
	}
	@JsonIgnore
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "house")
	@OrderBy(value="publishTime desc")
	public List<Comment> getComments() {
		return this.comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}

	@Transient
	public Integer getUserId() {
		return userId;
	}

	public void setUserId(Integer userId) {
		this.userId = userId;
	}

	@Transient
	public Integer getSalePayTypeId() {
		return salePayTypeId;
	}

	public void setSalePayTypeId(Integer salePayTypeId) {
		this.salePayTypeId = salePayTypeId;
	}

	@Transient
	public Integer getHouseTypeId() {
		return houseTypeId;
	}

	public void setHouseTypeId(Integer houseTypeId) {
		this.houseTypeId = houseTypeId;
	}

	@Transient
	public Integer getMetroStationId() {
		return metroStationId;
	}

	public void setMetroStationId(Integer metroStationId) {
		this.metroStationId = metroStationId;
	}

	@Transient
	public String getEmployeeName() {
		return employeeName;
	}

	public void setEmployeeName(String employeeName) {
		this.employeeName = employeeName;
	}

	@Transient
	public Integer getRentPayTypeId() {
		return rentPayTypeId;
	}

	public void setRentPayTypeId(Integer rentPayTypeId) {
		this.rentPayTypeId = rentPayTypeId;
	}

	@Transient
	public Integer getPropertyTypeId() {
		return propertyTypeId;
	}

	public void setPropertyTypeId(Integer propertyTypeId) {
		this.propertyTypeId = propertyTypeId;
	}

	@Transient
	public Integer getMetroId() {
		return metroId;
	}

	public void setMetroId(Integer metroId) {
		this.metroId = metroId;
	}

	@Column(name = "areaId", unique = false, nullable = true, insertable = false, updatable = false)
	public Integer getAreaId() {
		return areaId;
	}

	public void setAreaId(Integer areaId) {
		this.areaId = areaId;
	}

	@Column(name = "buildingId", unique = false, nullable = true, insertable = false, updatable = false)
	public Integer getBuildingId() {
		return buildingId;
	}

	public void setBuildingId(Integer buildingId) {
		this.buildingId = buildingId;
	}

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "house")
	@Where(clause="objType = \"house\" and extension != \"swf\"")
	public List<UploadFile> getPictures() {
		return pictures;
	}

	public void setPictures(List<UploadFile> pictures) {
		this.pictures = pictures;
	}
	
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "house")
	@Where(clause="objType = \"house\" and extension = \"swf\"")
	public List<UploadFile> getVideos() {
		return videos;
	}

	public void setVideos(List<UploadFile> videos) {
		this.videos = videos;
	}
	@JsonIgnore
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "house")
	@Where(clause="objType = \"house\"")
	public List<AuditHistory> getAuditHistory() {
		return auditHistory;
	}

	public void setAuditHistory(List<AuditHistory> auditHistory) {
		this.auditHistory = auditHistory;
	}
	
}